package com.github.tommas.admintpl.aop;

import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;

/**
 * Only try to proxy specified type of beans
 */
public class TypedAdvisorAutoProxyCreator<T> extends DefaultAdvisorAutoProxyCreator {
    private final Class<T> beanType;

    public TypedAdvisorAutoProxyCreator(Class<T> beanType) {
        this.beanType = beanType;
    }

    @Override
    protected boolean shouldSkip(Class<?> beanClass, String beanName) {
        if (super.shouldSkip(beanClass, beanName)) {
            return true;
        }

        return !beanType.isAssignableFrom(beanClass);
    }
}
